﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml.Serialization;

namespace TestEngine.Script.Task
{
    [Serializable]
    public class OpenWorkbookTask: ScriptTask
    {

        #region Public Properties

        public string FileName{
            get;set;
        }

        #endregion Public Properties


        protected override bool RunTaskSub(ScriptState state)
        {
            if (state.IsFailed) return false;
            if (String.IsNullOrEmpty(FileName))
            {
                state.Session.CreateNewWorkbook();
                return true;
            }
            else
            {
                var file = new FileInfo(FileName);
                if (file == null || !file.Exists)
                {
                    throw new ApplicationException("There is no valid file specified for the OpenWorkBookTask.");
                }
                state.Session.Open(file);
                return true;
            }
        }
    }
}
